package com.tianji.learning.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tianji.common.utils.BeanUtils;
import com.tianji.learning.domain.po.PointsBoardSeason;
import com.tianji.learning.domain.vo.PointsBoardSeasonVO;
import com.tianji.learning.mapper.PointsBoardSeasonMapper;
import com.tianji.learning.service.IPointsBoardSeasonService;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xjs
 */
@Service
public class PointsBoardSeasonServiceImpl extends ServiceImpl<PointsBoardSeasonMapper, PointsBoardSeason> implements IPointsBoardSeasonService {
    public PointsBoardSeason getByDate(LocalDateTime date) {
        return this.lambdaQuery()
                // where begin_time < date
                .lt(PointsBoardSeason::getBeginTime, date)
                .gt(PointsBoardSeason::getEndTime, date)
                .one();

    }

    @Override
    public List<PointsBoardSeasonVO> seasonsList() {
        List<PointsBoardSeason> list = this.list();
        return BeanUtils.copyList(list, PointsBoardSeasonVO.class);
    }

    @Override
    public PointsBoardSeason getByDate(LocalDate begin, LocalDate end) {
        return this.lambdaQuery().eq(PointsBoardSeason::getBeginTime,begin )
                .eq(PointsBoardSeason::getEndTime, end)
                .one();
    }
}
